import pymysql

conn = pymysql.connect(host="localhost", port=3306, user="root", password="root", database="test", charset="utf8")
cursor = conn.cursor()

try:
    cursor.execute("insert into students (name, gender) values ('ting', '女')")
    cursor.execute("insert into students1 (name, gender) values ('wuyutao', '男')")
    conn.commit()
except Exception as e:
    print(e)
    conn.rollback()


cursor.close()
conn.close()